﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;


namespace MPE
{
    public partial class ErrorSettings : Window
    {
        Properties.Settings param = Properties.Settings.Default;
        public ErrorSettings()
        {
            InitializeComponent();
            if_no_params.IsChecked = param.errorSettings[0] == '1';
            if_no_endif.IsChecked = param.errorSettings[1] == '1';
            if_elses_more_then_ifs.IsChecked = param.errorSettings[2] == '1';
            if_more_endifs.IsChecked = param.errorSettings[3] == '1';
            no_func.IsChecked = param.errorSettings[4] == '1';
            less_params.IsChecked = param.errorSettings[5] == '1';
            more_params.IsChecked = param.errorSettings[6] == '1';
            unknown_chars.IsChecked = param.errorSettings[7] == '1';
            bp_exist.IsChecked = param.errorSettings[8] == '1';
            bp_no_contain_gtbp.IsChecked = param.errorSettings[9] == '1';
            gtbp_no_exist.IsChecked = param.errorSettings[10] == '1';
            gtbp_forward_of_bp.IsChecked = param.errorSettings[11] == '1';
            no_params.IsChecked = param.errorSettings[12] == '1';
            func_no_params.IsChecked = param.errorSettings[13] == '1';
            bp_bad_format.IsChecked = param.errorSettings[14] == '1';
            gtbp_bad_format.IsChecked = param.errorSettings[15] == '1';
            js_bad_format.IsChecked = param.errorSettings[16] == '1';
            bad_brackets.IsChecked = param.errorSettings[17] == '1';
            bad_js.IsChecked = param.errorSettings[18] == '1';
            multilineComments.IsChecked = param.errorSettings[19] == '1';
            function_after_comment.IsChecked = param.errorSettings[20] == '1';

            if (param.whenCopyErrorMsg == 0) rb1.IsChecked = true;
            else if (param.whenCopyErrorMsg == 1) rb2.IsChecked = true;
            else if (param.whenCopyErrorMsg == 3) rb3.IsChecked = true;
        }
        void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) => DragMove();
        void If_no_params_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(0, 1).Insert(0, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void If_no_endif_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(1, 1).Insert(1, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void If_elses_more_then_ifs_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(2, 1).Insert(2, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void If_more_endifs_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(3, 1).Insert(3, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void No_func_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(4, 1).Insert(4, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Less_params_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(5, 1).Insert(5, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void More_params_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(6, 1).Insert(6, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Unknown_chars_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(7, 1).Insert(7, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Bp_exist_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(8, 1).Insert(8, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Bp_no_contain_gtbp_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(9, 1).Insert(9, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Gtbp_no_exist_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(10, 1).Insert(10, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Gtbp_forward_of_bp_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(11, 1).Insert(11, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void No_params_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(12, 1).Insert(12, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Func_no_params_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(13, 1).Insert(13, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Bp_bad_fornat_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(14, 1).Insert(14, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Gtbp_bad_format_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(15, 1).Insert(15, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Js_bad_format_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(16, 1).Insert(16, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Bad_brackets_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(17, 1).Insert(17, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void Bad_js_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(18, 1).Insert(18, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void MultilineComments_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(19, 1).Insert(19, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
        void RB_Checked(object sender, RoutedEventArgs e)
        {
            string name = (sender as RadioButton).Name;
            if (name[2] == '1')//Ctrl + одинарный клик
                param.whenCopyErrorMsg = 0;

            else if (name[2] == '2')//При одинарном клике
                param.whenCopyErrorMsg = 1;

            else if (name[2] == '3')//Никогда
                param.whenCopyErrorMsg = 2;
            param.Save();
        }
        void function_after_comment_Click(object sender, RoutedEventArgs e)
        { param.errorSettings = param.errorSettings.Remove(20, 1).Insert(20, (sender as CheckBox).IsChecked == true ? "1" : "0"); param.Save(); }
    }
}